<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改农业问题')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-agriQuestion-edit" th:object="${agriQuestion}">
        <input name="questionId" th:field="*{questionId}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">会员ID：</label>
            <div class="col-sm-8">
                <input name="memberId" th:field="*{memberId}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">作物ID：</label>
            <div class="col-sm-8">
                <input name="cropId" th:field="*{cropId}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">版块ID：</label>
            <div class="col-sm-8">
                <input name="sectionId" th:field="*{sectionId}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题：</label>
            <div class="col-sm-8">
                <textarea name="ask" class="form-control">[[*{ask}]]</textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">问题描述：</label>
            <div class="col-sm-8">
                <textarea name="describe" class="form-control">[[*{describe}]]</textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">图片：</label>
            <div class="col-sm-8">
                <input id="img" name="file" class="form-control" type="file" multiple/>
            </div>
            <input id="imgUrl" name="img" class="form-control" style="display: none"/>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">行政区划编码：</label>
            <div class="col-sm-8">
                <input name="areaCode" th:field="*{areaCode}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">行政区划名称：</label>
            <div class="col-sm-8">
                <input name="areaName" th:field="*{areaName}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">阅读数：</label>
            <div class="col-sm-8">
                <input name="readCount" th:field="*{readCount}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">问题状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('question_status')}">
                    <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}"
                           th:field="*{status}">
                    <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">提问的系统名称：</label>
            <div class="col-sm-8">
                <input name="sysName" th:field="*{sysName}" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="utils/js-utils :: imageUpload"/>
<script type="text/javascript" th:inline="javascript">
    var image = [[${agriQuestion.img}]];
    //
    var prefix = ctx + "agriculture/agriQuestion";
    $("#form-agriQuestion-edit").validate({
        focusCleanup: true
    });

    $(function () {
        imageUpload(9, "img", (code, data) => {
            if (code === 0) {
                $("#imgUrl").val(data);
            } else {
                alert(data);
            }
        }, image);
    })

    function submitHandler() {
        if ($.validate.form()) {

            let $imgUrl = $("#imgUrl");

            $imgUrl.show();
            var formData = $('#form-agriQuestion-edit').serialize();
            $imgUrl.hide();
            $.operate.save(prefix + "/edit", formData);

        }
    }
</script>
</body>
</html>
